<!--  -->
<template>
  <view class="body_view">
    <view class="activity_time">
      <view class="time">活动日期</view>
      <view class="time_one">{{activityStartDate}}/{{ activityEndDate }}</view>
    </view>
    <view class="activity_time">
      <view class="time">活动价格</view>
      <view class="time_one">{{price}}元</view>
    </view>
    <view class="audience">
      <view class="time">观众信息</view>
      <view class="qqqq">
        <view v-for="(item,index) in userList" :key="index" :class="item.status == 0 ? 'dis_view': 'dis_view1'"
          :data-id="index" @click="Select">
          <view class="dis_name">{{item.name}}</view>
        </view>
        <view class="btn_add" @click="btn_add">
          新增观众信息
        </view>
      </view>

    </view>
    <view class="btn_submit">
      <view class="btn_sub" @click="btn_submit">
        提交订单
      </view>
    </view>
  </view>
</template>

<script>
  //这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
  //例如：import 《组件名称》 from '《组件路径》';
  import {
    getAudience,
    getActivityDetail,
    preActivityOrder
  } from '@/common/request/api.js'
  export default {
    //import引入的组件需要注入到对象中才能使用
    components: {},
    data() {
      //这里存放数据
      return {
        userList: [],
        ids: '',
        activityStartDate: '',
        activityEndDate: "",
        price: '',
        userOne: "",
        activityName:''
      };
    },
    //监听属性 类似于data概念
    computed: {},
    //监控data中的数据变化
    watch: {},
    onLoad(options) {
      this.ids = options.id
      this.getActivityDetail1()
      this.getAudience1()
    },
    onShow() {
      this.getAudience1()

    },
    //方法集合
    methods: {
      //点击提交订单
      btn_submit() {
        console.log(this.userOne);
        if (this.userOne == "") {
          uni.showToast({
            title: '请选择观众信息',
            icon: 'none',
            duration: 2000
          })
        } else {
          console.log(this.userOne, "///----");
          this.preActivityOrder1()
        }

      },
      //下单预检查
      preActivityOrder1() {
        preActivityOrder({
          "activityId": this.ids,
          "idCard": this.userOne.idCard,
          "museumId": "16",
          "name": this.userOne.name,
          "phone": this.userOne.phone
        }).then((res) => {
          console.log(res.data.data,"/**-------");
          if(res.data.data){
            uni.navigateTo({
              url: '/pages/Wxpay/index?activityId='+this.ids + "&idCard=" + this.userOne.idCard + "&museumId=" + "16" + "&name=" + this.userOne.name + "&phone=" + this.userOne.phone + "&price=" + this.price + "&activityName=" + this.activityName
            })
          }
        })
      },
      //调用活动详情接口
      getActivityDetail1() {
        getActivityDetail(
          this.ids
        ).then((res) => {
          console.log(res, "我是活动详情");
          this.activityStartDate = res.data.data.activityStartDate
          this.activityEndDate = res.data.data.activityEndDate
          this.price = res.data.data.price
          this.activityName = res.data.data.activityName
        })
      },

      //调用观众信息接口
      getAudience1() {
        uni.showLoading({
          title: '加载中',
          mask: true
        })
        getAudience().then((res) => {
          console.log(res.data.data);
          if (res.data.code == 200) {
            res.data.data.map((item) => {
              console.log(item);
              return item.status = 0
            })
            uni.hideLoading()
            this.userList = res.data.data
          } else {
            uni.hideLoading()
            uni.showToast({
              title: res.data.msg,
              icon: 'none',
              duration: 2000
            })
          }
        })
      },
      btn_add() {
        uni.navigateTo({
          url: '/pages/Adduser/index'
        })
      },
      Select(e) {
        console.log(e);
        //点击当前的元素，把status改为1。当再次点击的时候，把status改为0。所有的元素只能有一个status的值为1
        //获取当前点击的元素的data-id
        let id = e.currentTarget.dataset.id;
        //把所有的status改为0
        this.userList.forEach((item, index) => {
          item.status = 0;
        })
        //把当前点击的元素的status改为1
        this.userList[id].status = 1;
        console.log(this.userList[id]);
        this.userOne = this.userList[id]
      },
    },
    beforeCreate() {}, //生命周期 - 创建之前
    //生命周期 - 创建完成（可以访问当前this实例）
    created() {

    },
    beforeMount() {}, //生命周期 - 挂载之前
    //生命周期 - 挂载完成（可以访问DOM元素）
    mounted() {

    },
    beforeUpdate() {}, //生命周期 - 更新之前
    updated() {}, //生命周期 - 更新之后
    beforeDestroy() {}, //生命周期 - 销毁之前
    destroyed() {}, //生命周期 - 销毁完成
    activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
  }
</script>
<style lang="less" scoped src="./index.less">

</style>